package cn.graydove.bot.listener;

import cn.graydove.bot.core.Processor;
import cn.graydove.bot.core.ProcessorManager;
import cn.graydove.bot.data.GroupServiceCacheData;
import cn.graydove.bot.model.entity.Account;
import cn.graydove.bot.service.AccountService;
import cn.graydove.bot.support.BotProperties;
import cn.graydove.bot.utils.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import net.mamoe.mirai.event.Event;
import net.mamoe.mirai.event.events.NewFriendRequestEvent;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class NewFriendProcessor implements Processor {

    private AccountService accountService;

    public NewFriendProcessor(AccountService accountService) {
        this.accountService = accountService;
    }

    @Override
    public boolean accept(Event event) {
        return NewFriendRequestEvent.class.equals(event.getClass());
    }

    @Override
    public void process(Event event) {
        NewFriendRequestEvent e = (NewFriendRequestEvent) event;

        long id = e.getFromId();
        log.info("收到QQ好友邀请：" + e.getFromId());
        List<Account> accounts = accountService.findAll();
        if (CommonUtils.in(id, accounts, Account::getQqNumber)) {
            log.info("同意");
            e.accept();
        } else {
            log.info("拒绝");
            e.reject();
        }

    }
}
